package com.asuka.mapper;

import com.asuka.entity.AddressBook;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    void insert(AddressBook addressBook);

    void deleteById(Long id);

    void update(AddressBook addressBook);

    List<AddressBook> selectList(AddressBook addressBook);

    @Select("select " +
            "id, user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default " +
            "from " +
            "address_book " +
            "where " +
            "id = #{id}")
    AddressBook selectById(Long id);

    @Update("update address_book set is_default = 0 where user_id = #{userId}")
    void updateDefaultAdress(Long userId);
}
